package org.example.sportdemo.service;

import org.example.sportdemo.entity.Competition;
import org.example.sportdemo.entity.Ground;
import org.example.sportdemo.mapper.CompetitionMapper;
import org.example.sportdemo.utils.PageUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class CompetitionService {

    @Autowired
    private CompetitionMapper eventMapper;

    public List<Competition> selectAll(){
        return eventMapper.selectAll();
    }

    public PageUtils queryPage(Map<String, Object> params) {
        //总数据
        List<Competition> competitionList = eventMapper.selectAll();
        //总条数
        Integer totalCount = eventMapper.selectCount();
        //当前页
        Integer currPage = Integer.valueOf((String) params.get("currPage"));
        //每页条数
        Integer pageSize = Integer.valueOf((String) params.get("pageSize"));
        return new PageUtils(totalCount,(Integer) pageSize,currPage,competitionList);
    }

    public void addCompetition(Competition competition) {

        Date date = new Date();
        competition.setCreate_time(date);
        eventMapper.addCompetition(competition);

    }

    public Competition selectById(Integer id) {
        return eventMapper.selectById(id);
    }

    public void updateCompetition(Competition competition) {
        eventMapper.updateCompetition(competition);
    }

    public void deleteByIds(Integer[] ids) {
        eventMapper.deleteByIds(ids);
    }

    public List<Ground> selectForHot() {
        return eventMapper.selectForHot();
    }
}
